home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / amassm.lha / 68000MacLanguage.course1.pp / 68000MacLanguage.course1
Encoding:
Text File  |  1990-09-07  |  57.2 KB  |  1,687 lines

  1.  
  2.   Another great doc for the budding assembly langage programmers.
  3.          Parts 1-5 of of the 68000 Machine Language Course
  4.                   Brought to you by Sewer Software
  5.  
  6.      68000 MACHINE LANGUAGE COURSE PART I by Mark van de Boer
  7.  
  8.  As  the  title  already says this is the first  part  of  an 68000 
  9.  assembly language programming course.  This course is intended for 
  10.  people  who  already have a little experience with programming  in 
  11.  assembly  language  on microprocessors like the 6502 (6510  is  in 
  12.  fact the same) and the 68xx (like 6800,  6801, 6805, 6809) series. 
  13.  In   this  course  these  two  microprocessor-families   will   be 
  14.  referenced by their most famous members, the 6502 and the 6809. At 
  15.  this  time it is not exactly known how many articles  this  course 
  16.  will have. I think it will be about six articles long.
  17.  Now  I will describe some features of the 68000.  The 68000  is  a 
  18.  sixteen-bit  microprocessor.  This means that an opcode is  always 
  19.  sixteen bits (On the 6502 and 6809 an opcode is 8 bits,  therefore 
  20.  they are called 8-bit microprocessors).  The databus of the  68000 
  21.  is  16 bits wide,  this means that 16 bits can be  transferred  at 
  22.  once  by the 68000 (The 6502 and 6809 both have a databus that  is 
  23.  eight  bits wide,  so they can transfer 8 bits at  once).
  24.  
  25.  
  26.  Another  important feature of the 68000 is its impressive  set  of 
  27.  registers.  First there are the eight data registers, numbered D0-
  28.  D7. They are 32 bits wide and can be used for operations on 8-bit, 
  29.  16-bit and 32-bit quantities.  Data registers can be compared with 
  30.  the  A-register  (Accumulator)  on  the  6502  and   6809,   their 
  31.  function  same,  but  the use of the data registers is  much  more 
  32.  convenient.   Second,  there  are  the  eight  address  registers, 
  33.  numbered from A0-A7.  They are 32 bits wide as well and their only 
  34.  use  is  in  addressing memory.  However,  the upper  8  bits  are 
  35.  ignored  by  the  68000 since its address bus is  'only'  24  bits 
  36.  wide,  meaning  that the 68000 can address up to 16  megabytes  of 
  37.  memory.  Register  A7  has a special function;  it is  called  the 
  38.  system  stackpointer.  This  means  that  if  you  execute  a  JSR 
  39.  instruction,  some data will be saved on the address contained  in 
  40.  this  register.  By the way,  you can use every  address  register 
  41.  very  easily as a stackpointer.  The third class consists  of  one 
  42.  register, the PC (program counter). This register always  contains
  43.  the address of the instruction  to  be  executed next.  Of course,
  44.  the upper eight bits of the PC are also ignored. The  fourth class
  45.  consists of one 16 bit register, the status register, called SR.
  46.  
  47.  
  48.  This register is built up like this:
  49.  
  50.  -------------------------------------------------------------
  51.  | T |   | S |   | I0| I1| I2|   |   |   | X | N | Z | V | C |
  52.  -------------------------------------------------------------
  53.      system-byte             |          user-byte
  54.  
  55.  The  upper 8 bits are called the system byte.  This byte  contains 
  56.  information that is important to the system.  Normally you can not 
  57.  change this byte if you run an application.  Bit 15 is called  the 
  58.  trace-bit.  If  this  bit is set,  every time after  executing  an 
  59.  instruction  the 68000 will generate an exception (This is  called 
  60.  an interrupt on the 6502 and 6809). This is especially useful when 
  61.  debugging programs. Bit 13 is called the supervisor bit. When this 
  62.  bit  is  set the 68000 is in supervisor mode;  when  this  bit  is 
  63.  cleared,  however,  the 68000 is in user mode.  When executing  in 
  64.  supervisor  mode,  the 68000 can execute the so called  privileged 
  65.  instructions,  which are not available in user mode.  For example, 
  66.  it is illegal trying to change the upper 8 bits of the SR when  in 
  67.  user  mode.  Bits 8,  9 and 10 are called the interrupt  mask.  In 
  68.  total they can contain eight different values ranging from zero to 
  69.  seven.  For  instance,  if  bits  8 and 10 are set and  bit  9  is 
  70.  cleared,  the  value of the interrupt mask is 5.  This means  that 
  71.  only interrupts with a level of 5 and higher are recognized by the
  72.  68000  and  interrupts  with a level lower  than  5  are  ignored. 
  73.  Interrupts of level 7 can be considered as non maskable interrupts
  74.  (compare this to the NMI  on the 6502 and 6809).  The lower 8 bits
  75.  are   called  the  conditioncode  register,   CCR  (this  can   be 
  76.  compared to the CC of the 6502 and 6809). The CCR contains 5 bits,
  77.  which contain useful data.  Bit 0 is the carry-flag (C),  bit 1 is 
  78.  the overflow-flag (V),  bit 2 is the zero-flag (Z),  bit 3 is  the 
  79.  negative-flag  (N).  The  meanings of these bits are  exactly  the 
  80.  same as on the 6502 and 6809.  Then there is bit 4 which is called 
  81.  the extend-flag (X).  It is nearly exactly the same as the  carry-
  82.  flag,  but  is not affected by every instruction that affects  the 
  83.  carry-flag. This feature of the extend-flag  is  especially useful
  84.  when  using  multiple precision  arithmetic,  e.g.  adding  64-bit 
  85.  numbers.
  86.  
  87.  
  88.  Another  feature of the 68000 is its ability to access three  data 
  89.  formats: byte (8 bits), word (16 bits) and longword (32 bits). You 
  90.  can  indicate  this  with a suffix  in  the  mnemonic  field.  The 
  91.  suffixes are .b for byte,  .w for word and .l for  longword.  E.g. 
  92.  asr.b d0  ,   asr.w   d0    , asr.l   d0. These instructions shift 
  93.  data register d0 one place to the right.
  94.  I  think  this is enough new stuff for today.  Next  time  I  will 
  95.  explain  the  addressing  modes of the  68000.  If  you  have  any 
  96.  comments  or  questions  on this  article,  please  write  to  the 
  97.  correspondence address and I'll take your notes into account. 
  98.  
  99.  A good Motorola MC 68000 book is:
  100.  The Motorola 68000 programming guide,  which unfortunately is  not 
  101.  available in the stores.
  102.  Further there are a number of books on the 68000.  I would like to 
  103.  mention the book written by Lance Leventhal & Gerry Kane,  which I 
  104.  think gives good value for its money.  Another good book is  Steve 
  105.  Williams' "Programming the 68000". 
  106.  
  107.  
  108.   
  109.   68000 ASSEMBLY LANGUAGE COURSE PART II by Mark van den Boer
  110.  
  111.  Welcome to part II of this course.  In part I,  some fundamentals 
  112.  of  the 68000 were shown.  In this part,  I will show  you  which 
  113.  addressing modes the 68000 uses.  First an example of  addressing 
  114.  modes which the 6502 and 6809 use:
  115.  
  116.  lda #10   * immediate addressing
  117.  lda $10   * zero-page (6502) or direct-page addressing (6809)
  118.  inx       * inherent (6502)
  119.  inca      * inherent (6809)
  120.  
  121.  Now, what does a line of code in 68000 assembler look like?
  122.  
  123.  LABEL   OPCODE  OPER1,OPER2      COMMENT
  124.  
  125.  The meanings of these fields are:
  126.  label:   A  name  given to this line  of  code.  Some  assemblers 
  127.  require  a :  to follow the label-name.  This  field  is 
  128.  optional.
  129.  
  130.  
  131.  opcode:  This field specifies the operation you wish to perform. 
  132.           It is the only field that isn't optional.  Depending  on 
  133.           the opcode the 68000 expects 0, 1 or 2 operands.
  134.  oper1:   The  first  operand  to  appear  with  the  opcode.  The 
  135.           appearance  of  this  field  depends  on  the  specified 
  136.           opcode.
  137.  oper2:   The  second  operand  to appear  with  the  opcode.  The 
  138.           appearance of this field depends (surprise, surprise) on 
  139.           the specified opcode.
  140.  comment: Another optional field which is used for commenting  all 
  141.           tricks  people put in their  programs.  Most  assemblers 
  142.           require a * as the first character of the comment field. 
  143.           The comment field is optional.
  144.  
  145.  Now what does an addressing mode do? An addressing mode specifies 
  146.  on which data the opcode (instruction) must operate.
  147.  The  68000 has a total of 14 addressing modes,  all of which  now 
  148.  will  explained.  As examples in all addressing modes I will  use 
  149.  the MOVE instruction. MOVE can have the .b, .w and .l suffixes as 
  150.  mentioned in part I of the course. The MOVE instruction moves the 
  151.  data specified by oper1 to the place specified by oper2.   
  152.  
  153.  Example:  MOVE.B $1,$2 performs exactly the same operation as the 
  154.  following 6502 and 6809 code: LDA $1    STA $2.
  155.  
  156.  The addressing modes:
  157.  
  158.  1. Inherent addressing
  159.  
  160.  In  this  addressing mode there are no operands  since  they  are 
  161.  already supplied by the opcode.
  162.  E.g.: RESET    * reset all peripherals
  163.  RESET is an 68000 instruction which is used to reset all the 
  164.  peripherals.
  165.  
  166.  2. DATA REGISTER DIRECT ADDRESSING
  167.  
  168.  Assembler syntax: Dn (n can range from 0 to 7)
  169.  In this addressing mode a data register contains the operand.
  170.  E.g.:
  171.  
  172.  
  173.  
  174.  
  175.  Instruction          Before             After
  176.  MOVE.B D1,D0      d0=ffffffff         d0=ffffff67
  177.                    d1=01234567         d1=01234567
  178.  MOVE.W D1,D0      d0=ffffffff         d0=ffff4567
  179.                    d1=01234567         d1=01234567
  180.  MOVE.L D1,D0      d0=ffffffff         d0=01234567
  181.                    d1=01234567         d1=01234567
  182.  
  183.  As  you might have noticed,  an instruction with .b as  a  suffix 
  184.  only  changes  the  lowest  8  bits  of  the   destination,   and 
  185.  instructions  with .w as a suffix only change the lowest 16  bits 
  186.  of the destination.  Instructions with .l as a suffix change  all 
  187.  32 bits of the destination.
  188.  
  189.  3. ADDRESS REGISTER DIRECT ADDRESSING
  190.  
  191.  Assembler syntax: An (n can range from 0 to 7)
  192.  In this addressing mode an address register contains the operand. 
  193.  Byte  operators  (those with .b suffix) are not allowed  in  this 
  194.  addressing mode. When using the address register as a destination 
  195.  and  it  is a word operation (suffix is .w),  the word  is  sign-
  196.  extended into a longword.  This means that during a  wordtransfer 
  197.  into a data register the upper 16 bits are filled with the  value 
  198.  of  the  most-significant bit (this is bit 15) of  the  word.  An 
  199.  example below will show you how it's done.
  200.  E.g.:
  201.  
  202.  Instruction          Before             After
  203.  MOVE.W A1,D0       d0=ffffffff        d0=ffff4567
  204.                     a1=01234567        a1=01234567
  205.  MOVE.W D0,A1       d0=01234567        d0=01234567
  206.                     a1=ffffffff        a1=00004567  <- extend!!
  207.  MOVE.W D0,A1       d0=0000ffff        d0=0000ffff
  208.                     a1=00000000        a1=ffffffff  <- extend!!
  209.  MOVE.L A1,D0       d0=ffffffff        d0=01234567
  210.                     a1=01234567        a1=01234567
  211.  
  212.  4. ADDRESS REGISTER INDIRECT ADDRESSING
  213.  
  214.  Assembler syntax: (An)   (n between 0 and 7)
  215.  In  this  addressing  mode,  the address  register  contains  the 
  216.  address of the operand.  In assembler this is being denotated  by 
  217.  putting parentheses around an address registers name,  e.g. (a0). 
  218.  The contents of a0 points to the address where the data has to be 
  219.  fetched from. When using word (.w) or longword (.l) addressing it 
  220.  is  absolutely  necessary that the address register  contains  an 
  221.  even number (I will explain the reason for this in a  forthcoming 
  222.  article).
  223.  E.g.:
  224.  
  225.  Instruction          Before             After
  226.  MOVE.L (A1),D0    d0=ffffffff        d0=01234567
  227.                    a1=00001000        a1=00001000
  228.              address $1000 contains 01234567
  229.  MOVE.L D0,(A1)    d0=76543210        d0=76543210
  230.                    a1=00001000        a1=00001000
  231.              address $1000 now contains 76543210
  232.  
  233.  5. ADDRESS REGISTER INDIRECT ADDRESSING WITH POST-INCREMENT
  234.  
  235.  Assembler syntax: (An)+     (n between 0 and 7)
  236.  This  addressing  mode resembles the  address  register  indirect 
  237.  addressing mode. The only difference is that after having fetched 
  238.  or  stored the data,  the address register  is  incremented.  The 
  239.  increment depends on the suffix used in the opcode. If the suffix 
  240.  is  .b then the address register will be incremented by  one.  If 
  241.  the suffix is .w then the address register will be incremented by 
  242.  two (one word is two bytes). If the suffix is .l then the address 
  243.  register  will  be  incremented by four  (one  longword  is  four 
  244.  bytes). In assembler this addressing mode is denotated by putting 
  245.  the address register within parentheses followed by a + sign. For 
  246.   example: (a7)+
  247.  E.g.:
  248.  
  249.  Instruction          Before             After
  250.  MOVE.L (A1)+,D0   d0=ffffffff        d0=01234567
  251.                    a1=00001000        a1=00001004
  252.              address $1000 contains 01234567
  253.  MOVE.W (A1)+,D0   d0=ffffffff        d0=ffff0123
  254.                    a1=00001000        a1=00001002
  255.              address $1000 contains 01234567
  256.  MOVE.B (A1)+,D0   d0=ffffffff        d0=ffffff01
  257.                    a1=00001000        a1=00001001
  258.              address $1000 contains 01234567
  259.  MOVE.L D0,(A1)+   d0=76543210        d0=76543210
  260.                    a1=00001000        a1=00001004
  261.              address $1000 now contains 76543210
  262.  
  263.  6. ADDRESS REGISTER INDIRECT ADDRESSING WITH PRE-DECREMENT
  264.  
  265.  Assembler syntax: -(An)     (n between 0 and 7)
  266.  This  addressing  mode resembles the  address  register  indirect 
  267.  addressing  mode.  The  only  difference  is  that  after  before 
  268.  fetching  or  storing the data,  the address register  is  decre-
  269.  mented.  The decrement depends on the suffix used in the  opcode. 
  270.  If the suffix is .b then the address register will be decremented 
  271.  by  one.  If the suffix is .w then the address register  will  be 
  272.  decremented by two (one word is two bytes).  If the suffix is  .l 
  273.  then  the  address  register will be  decremented  by  four  (one 
  274.  longword  is four bytes).  In assembler this addressing  mode  is 
  275.  denotated  by  putting the address  register  within  parentheses 
  276.  preceded by a - sign. For example: -(a7)
  277.  E.g.: 
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  Instruction          Before             After
  286.  MOVE.L -(A1),D0   d0=ffffffff        d0=01234567
  287.                    a1=00001004        a1=00001000
  288.              address $1000 contains 01234567
  289.  MOVE.W -(A1),D0   d0=ffffffff        d0=ffff4567
  290.                    a1=00001004        a1=00001002
  291.              address $1000 contains 01234567
  292.  MOVE.B -(A1),D0   d0=ffffffff        d0=ffffff67
  293.                    a1=00001004        a1=00001003
  294.              address $1000 contains 01234567
  295.  MOVE.L D0,-(A1)   d0=76543210        d0=76543210
  296.                    a1=00001004        a1=00001000
  297.              address $1000 now contains 76543210
  298.  
  299.  7. ADDRESS REGISTER INDIRECT ADDRESSING WITH DISPLACEMENT
  300.  
  301.  Assembler syntax: w(An)    (w stands for word displacement)
  302.  This  addressing  is  also rather  similar  to  address  register 
  303.  indirect  addressing.  The only difference lies in the fact  that 
  304.  before  fetching or moving the data a 16-bit signed  displacement 
  305.  is  added  to the contents of the address register  (the  address 
  306.  register  itself does not change).  In assembler this  addressing 
  307.  mode  is  denotated  by enclosing the address  register  name  in 
  308.  parentheses  preceded by a 16-bit constant.  For  example:  8(a6) 
  309.  denotes  the memory location whose address is the contents of  a6 
  310.  plus 8.  This addressing method comes in very handy when  passing 
  311.  parameters to subroutines.
  312.  By the way, did you ever wonder why the ATARI ST has a resolution 
  313.  of  640  by  400  pixels?
  314.  Here's one reason:  640*400=256000 bits=32000 bytes.  Since 32000 
  315.  bytes  can  be  addressed using 16  bits,  the  address  register 
  316.  indirect with displacement is an easy way to address the screen.
  317.  E.g.: 
  318.  
  319.  Instruction          Before             After
  320.  MOVE.L 8(A1),D0   d0=ffffffff        d0=01234567
  321.                    a1=00001000        a1=00001000
  322.              address $1008 contains 01234567
  323.  MOVE.L D0,-6(A1)  d0=76543210        d0=76543210
  324.                    a1=00001006        a1=00001006
  325.              address $1000 now contains 76543210
  326.  
  327.  
  328.  
  329.  8. ADDRESS REGISTER INDIRECT ADDRESSING WITH INDEX
  330.  
  331.  Assembler syntax: b(An,Rn.w) or b(An,Rn.l)
  332.  (  b  stands for byte,  w and l for word and longword and  R  for 
  333.  register).
  334.  This  addressing mode makes it possible to add a  variable  index 
  335.  (contained in an address or data register) to an address register 
  336.  and  also an eight bit signed displacement.   The variable  index 
  337.  may be either word or longword.  Both the index and  displacement 
  338.  are sign extended before they are added to the address register.
  339.  E.g.:
  340.  
  341.  Instruction            Before             After
  342.  MOVE.L 8(A1,A0.L),D0   d0=ffffffff        d0=01234567
  343.                         a1=00001000        a1=00001000
  344.                         a0=00078000        a0=00078000
  345.                     address $79008 contains 01234567
  346.  MOVE.L 8(A1,A0.W),D0   d0=ffffffff        d0=01234567
  347.                         a1=00001000        a1=00001000
  348.                         a0=00078000        a0=00078000
  349.  *** a0.w=8000 -> sign-extend gives ffff8000 ***
  350.                     address $ffff8008 contains 01234567
  351.  MOVE.W 8(A1,D0.L),D0   d0=0001fffe        d0=00010123
  352.                         a1=00001000        a1=00001000
  353.  *** 00001000 (contents of a1)
  354.      0001fffe (contents of d0.l)
  355.      00000008 (sign-extended byte displacement)
  356.      ---------
  357.      00021006
  358.                     address $21006 contains 01234567
  359.  MOVE.L 8(A1,D0.W),D0   d0=0001fffe        d0=01234567
  360.                         a1=00001000        a1=00001000
  361.  *** 00001000 (contents of a1)
  362.      fffffffe (sign-extended contents of d0.w)
  363.      00000008 (sign-extended byte displacement)
  364.      ---------
  365.      00001006
  366.                     address $1006 contains 01234567 
  367.  
  368.  9. ABSOLUTE SHORT ADDRESSING
  369.  
  370.  Assembler syntax: x  (x is a 16 bit constant)
  371.  With  absolute short addressing it is only possible to specify  a 
  372.  16  bit constant.  At execution time the 68000 sign  extends  the 
  373.  word into a long address,  meaning that only addresses 0 to  7fff 
  374.  and ffff8000 to ffffffff can be addressed using this  form.  This 
  375.  addressing mode can be compared with zero-page addressing on  the 
  376.  6502 and direct-page addressing on the 6809.Like on the 6502  and 
  377.  6809  this mode is faster than any other  mode.  This  addressing 
  378.  mode  can be compared with zero-page addressing on the  6502  and 
  379.  direct-page addressing on the 6809.
  380.  By the way, on the Atari ST, the lower 32 K of memory can only be 
  381.  accessed in supervisor-mode (the S-bit in SR is set, see part I).
  382.  E.g.:
  383.  
  384.  Instruction            Before             After
  385.  MOVE.L $1234,D0      d0=ffffffff       d0=01234567
  386.                      address 1234 contains 01234567
  387.                     ( the $ sign is used to denote a hex digit)
  388.  MOVE.L $8000,D0      d0=ffffffff       d0=76543210
  389.                      address $ffff8000 contains 76543210 
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  10. ABSOLUTE LONG ADDRESSING
  396.  
  397.  Assembler syntax: l   (l is 32 bit constant)
  398.  With this addressing mode a long address is supplied.  It is very 
  399.  similar to absolute short addressing.
  400.  E.g.:
  401.  Instruction              Before             After
  402.  MOVE.L $12345678,D0   d0=ffffffff         d0=01234567
  403.                        address $00345678 contains 01234567
  404.  Note  that since the address bus is only 24 bits wide  the  upper 
  405.  byte of the address is ignored by the 68000. 
  406.  
  407.  11. PROGRAM COUNTER WITH DISPLACEMENT
  408.  
  409.  Assembler syntax: x(PC)    (x is a 16 bit constant)
  410.  This  addressing  mode is in fact the same  as  address  register 
  411.  indirect  with  displacement.  The only difference  is  that  the 
  412.  address register is replaced with the PC (the PC is in fact  also 
  413.  an address register).
  414.  E.g.:
  415.  
  416.  
  417.  Instruction          Before             After
  418.  MOVE.L 8(PC),D0   d0=ffffffff        d0=01234567
  419.                    pc=00001000        pc=00001000
  420.              address $1008 contains 01234567
  421.  
  422.  12. PROGRAM COUNTER WITH INDEX
  423.  
  424.  Assembler syntax: b(PC,Rn.L) or b(PC,Rn.w)   (b is 8 bits)
  425.  This  mode  is  in  fact  the  same  address  register   indirect 
  426.  addressing with index.
  427.  E.g.:
  428.  
  429.  Instruction            Before             After
  430.  MOVE.L 8(PC,A0.L),D0   d0=ffffffff        d0=01234567
  431.                         pc=00001000        pc=00001000
  432.                         a0=00078000        a0=00078000
  433.                     address $79008 contains 01234567
  434.  MOVE.L 8(PC,A0.W),D0   d0=ffffffff        d0=01234567
  435.                         pc=00001000        pc=00001000
  436.                         a0=00078000        a0=00078000
  437.  *** a0.w=8000 -> sign-extend gives ffff8000 ***
  438.                     address $ffff8008 contains 01234567
  439.  MOVE.W 8(PC,D0.L),D0   d0=0001fffe        d0=00010123
  440.                         pc=00001000        pc=00001000
  441.  *** 00001000 (contents of pc)
  442.      0001fffe (contents of d0.l)
  443.      00000008 (sign-extended byte displacement)
  444.      ---------
  445.      00021006
  446.                     address $21006 contains 01234567
  447.  MOVE.L 8(PC,D0.W),D0   d0=0001fffe        d0=01234567
  448.                         pc=00001000        pc=00001000
  449.  *** 00001000 (contents of pc)
  450.      fffffffe (sign-extended contents of d0.w)
  451.      00000008 (sign-extended byte displacement)
  452.      ---------
  453.      00001006
  454.                     address $1006 contains 01234567
  455.  
  456.  13. IMMEDIATE ADDRESSING
  457.  
  458.  Assembler syntax: #x   (x is byte, word or longword)
  459.  The  data for the operation is the value x.  Programmers  of  the 
  460.  6502  and 6809 will recognize this addressing mode.  For  example 
  461.  (6502 and 6809) LDA #$21.
  462.  E.g.:
  463.  
  464.  Instruction               Before             After
  465.  MOVE.L #$A03B4C11,D0    d0=00000000       d0=a03b4c11 
  466.  
  467.  14. STATUS REGISTER ADDRESSING
  468.  
  469.  Assembler syntax: SR or CCR
  470.  This mode is used to control the contents of this  register.  See 
  471.  part  I  of this course for the individual meanings of  the  bits 
  472.  contained  in this register.  Changes to the SR can only be  made 
  473.  when in user-mode. Changes to the CCR can be made in any mode.
  474.  E.g.:
  475.  
  476.  Instruction            Before             After
  477.  MOVE.W SR,D0        d0=87654321        d0=87652700
  478.                      sr=2700            sr=2700
  479.  MOVE.W #$0500,SR    sr=2700            sr=0500
  480.  Notice that the 68000 was in supervisor mode before executing the 
  481.  instruction  but  after  completion it is  in  user  mode!!  This 
  482.  operation isn't possible the other way around.
  483.  To  conclude  this  part,  I  will give  you  a  summary  of  the 
  484.  addressing modes of the 68000.
  485.  
  486.  SYNTAX          NAME
  487.  -----------------------------------
  488.  Dn          | Data register direct
  489.  An          | Address register direct
  490.  (An)        | Address register indirect
  491.  (An)+       | Address register indirect with post-increment
  492.  -(An)       | Address register indirect with pre-decrement
  493.  w(An)       | Address register with displacement
  494.  b(An,Rn)    | Address register with index
  495.  w           | Absolute short
  496.  l           | Absolute long
  497.  w(PC)       | PC with displacement
  498.  b(PC,Rn)    | PC with index
  499.  #x          | Immediate
  500.  SR or CCR   | Status register
  501.  
  502.  
  503.  
  504.  
  505.  b is a byte constant
  506.  w is a word constant
  507.  l is a long constant
  508.  x any of b, l or w
  509.  n is a register number ranging from 0 to 7
  510.  R is a register specifier, either A or D
  511.  
  512.  If you have any comments on these courses, please let me know!
  513.  
  514.  
  515.  
  516. 68000 MACHINE LANGUAGE COURSE PART III by Mark van den Boer
  517.  
  518. In  part  I & II the basics of programming the  68000  have  been 
  519. introduced.  In the following parts of this course I will discuss 
  520. the  instructions of the 68000.  To understand this part and  the 
  521. coming  ones  I suggest you keep a printed copy of part  II  (the 
  522. addressing modes) in close range, so you can look things up.
  523. Before discussing the individual instructions of the 68000 I will 
  524. divide its instructions into eight classes.
  525. These classes are:
  526. - Data movement operations. 
  527. - Integer  arithmetic  operations  (on  two's  complement  binary 
  528. numbers.
  529. - Logical operations.
  530. - Shift and rotate operations.
  531. - Bit manipulation operations.
  532. - Binary Coded Decimal (BCD) operations.
  533. - Program control instructions.
  534. - System control operations.
  535.  
  536.  
  537.  
  538. In  this  part  and  the following  parts  all  classes  will  be 
  539. discussed.  This approach is somewhat different of the one chosen 
  540. by  other authors (the alphabetic order).  For an explanation  of 
  541. the source and destination addressing modes I refer to the  table 
  542. at the end of part II.
  543. To  specify  the  operands  of  the  instructions  the  following 
  544. conventions are used:
  545.  
  546. Rn   stands for either a data- or addressregister
  547. An   stands for an address register
  548. Dn   stands for a data register
  549. <ea> stands  for an effective address operand.  This  means  that 
  550.      after the operand after evaluation must yield an address.
  551. #    stands for immediate data
  552.  
  553. All other symbols which appear in either field of the 
  554. instruction's assembler syntax will be explained.
  555. One  suggestion  before  the  explanation  starts:   Since  68000 
  556. instructions  may operate on bytes,  words and longwords,  it  is 
  557. wise  to always specify which size you want to  manipulate.  This 
  558. way will considerably reduce the amount of very hard to find bugs 
  559. in your program.  Since assemblers take defaults when no size  is 
  560. specified you can get very odd results.  E.g.  BSET  (instruction 
  561. will  be explained later) operates only on bytes  and  longwords. 
  562. The assembler makes the default for you. Suppose you want a word-
  563. operation  to  be  performed  and you  don't  specify  the  size, 
  564. thinking  that the default is nearly always word.  Well  in  this 
  565. case the default isn't word, so the assembler thinks your code is 
  566. alright, but it doesn't do what you want.
  567.  
  568. Data movement operations
  569.  
  570. Instruction:   EXG
  571. Syntax:        EXG Rn,Rn
  572. Data sizes:    Long
  573. Condition codes affected: None
  574. Addressing modes:
  575. source:   Dn
  576.           An
  577. destination:
  578.           Dn
  579.           An
  580. Function:      Exchange the contents of two registers
  581.  
  582. Example:
  583. Instruction              Before         After
  584. EXG a0,d0                d0=11111111    d0=22222222
  585.                          a0=22222222    a0=11111111
  586.  
  587. Instruction:   LEA
  588. Syntax:        LEA <ea>,An
  589. Data sizes:    Long
  590. Condition code affected: None
  591. Addressing modes:
  592. Source:
  593.      (An)
  594.      w(An)
  595.      b(An,Rn)
  596.      w
  597.      l
  598.      w(PC)
  599.      b(PC,Rn)
  600. Destination:
  601.      An
  602. Function:      Load an address register with a value.  LEA stands 
  603.                for Load Effective Address.
  604. Example:
  605. Instruction              Before         After
  606. LEA (a1),a0              a0=00000000    a0=12345678
  607.                          a1=12345678    a1=12345678
  608. LEA 9(a0),a0             a0=00111111    a0=00111119
  609. LEA 5(a0,d0.w)           a0=10000100    a0=10001111
  610.                          d0=0000100b    d0=0000100b
  611. LEA $12345678,a0         a0=00000000    a0=12345678
  612.  
  613. Instruction:   LINK
  614. Syntax:        LINK An,#
  615. Data sizes:    None
  616. Condition codes affected: None
  617. Addressing modes:
  618. source:   An
  619. destination:
  620.           #w
  621.  
  622.  
  623.  
  624.  
  625.  
  626. Function:      Create  temporary  space  on  stack.   The  source 
  627.                (address register) is pushed onto the  stack,  the 
  628.                stack-pointer  (a7) is copied into the source  and 
  629.                the destination is added to the stack-pointer. The 
  630.                destination-operand  is usually  negative  because 
  631.                the  68000-stack grows downward  in  memory.  This 
  632.                instruction  is  used  very  much  by   high-level 
  633.                languages such as C and PASCAL.  This  instruction 
  634.                has  the  advantage  that  local  variables  in  a 
  635.                subroutine  can  be accessed through  the  source-
  636.                address register. 
  637.                E.g.:  Every C-compiler on the Atari St uses  this 
  638.                instruction at the beginning of every subroutine.
  639. Example:
  640. Instruction              Before         After
  641. LINK a6,#-4              a6=12345678    a6=44444444
  642.                          a7=44444448    a7=44444440
  643. Let's analyse: First  a6 is pushed onto the  stack:  a7=44444444. 
  644.                Then the stack-pointer is copied into a6. Then the 
  645.                destination-operand is added to a7.
  646.  
  647.  
  648. Instruction:   UNLK
  649. Syntax:        UNLK source
  650. Data sizes:    None
  651. Condition codes affected: None
  652. Addressing modes:
  653. source:   An
  654. Function:      The opposite of LINK. Also used by all C-compilers 
  655.                at the end of functions.
  656. Example:
  657. For values see LINK
  658. Instruction              Before         After
  659. UNLK a6                  a6=44444444    a6=12345678
  660.                          a7=????????    a7=44444448
  661.                First a6 is copied into a7:  a7=44444444.  Then a6 
  662.                is pulled from the stack,  which yields the  final 
  663.                values of a6 and a7
  664.  
  665. Instruction:   MOVE
  666. Syntax:        MOVE <ea>,<ea>
  667. Data sizes:    Byte, Word, Long
  668. Condition codes affected: N,Z (conditionally set/cleared),
  669.                           V,C (always cleared)
  670. Addressing modes:
  671. source:   Dn
  672.           An
  673.           (An)
  674.           (An)+
  675.           -(An)
  676.           w(An)
  677.           b(An,Rn)
  678.           w
  679.           l
  680.           w(PC)
  681.           b(PC,Rn)
  682.           #x
  683. destination:
  684.           Dn
  685.           (An)
  686.           (An)+
  687.           -(An)
  688.           w(An)
  689.           b(An,Rn)
  690.           w
  691.           l
  692. Function:      Move   the   contents  of  the   source   to   the 
  693.                destination.   This   instruction  is   the   most 
  694.                frequently  used  68000-instruction  and  is  very 
  695.                powerful.  Note  that the  PC-relative  addressing 
  696.                modes are not allowed as destination-operand. This 
  697.                seems illogical, but there's a good reason for it. 
  698.                In the view of the designers at Motorola it is bad 
  699.                practice to have self-modifying code in a program.
  700. Example:
  701. See part II of this course for examples on the MOVE-instruction.
  702.  
  703. Instruction:   MOVE to CCR
  704. Syntax:        MOVE <ea>,CCR
  705. Data sizes:    Byte
  706. Condition  codes  affected:   All  as  a  direct  result  of  the 
  707. instruction.
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714. Addressing modes:
  715. source:   Dn
  716.           (An)
  717.           (An)+
  718.           -(An)
  719.           w(An)
  720.           b(An,Rn)
  721.           w
  722.           l
  723.           w(PC)
  724.           b(PC,Rn)
  725.           #x
  726. Function: Set some condition codes. With this instruction you can 
  727.           clear/set the N,Z,V,C and X flag.
  728. Example: See part II
  729.  
  730. Instruction:   MOVE to SR
  731. Syntax:        MOVE <ea>,SR
  732. Data sizes:    Word
  733. Condition  codes  affected:   All  as  a  direct  result  of  the 
  734. instruction. This instruction is priviliged .
  735.  
  736. Addressing modes:
  737. source:   Dn
  738.           (An)
  739.           (An)+
  740.           -(An)
  741.           w(An)
  742.           b(An,Rn)
  743.           w
  744.           l
  745.           w(PC)
  746.           b(PC,Rn)
  747.           #x
  748. Function: Set condition codes.
  749. Example: See part II
  750.  
  751. Instruction:   MOVE from SR
  752. Syntax:        MOVE SR,<ea>
  753. Data sizes:    Word
  754. Condition codes affected: None.
  755. Addressing modes:
  756. source:   SR
  757.  
  758. destination:
  759.           Dn
  760.           (An)
  761.           (An)+
  762.           -(An)
  763.           w(An)
  764.           b(An,Rn)
  765.           w
  766.           l
  767. Function: Request   condition  codes.   This  function   is   not 
  768.           priviliged on the 68000 and 68008, but is priviliged on 
  769.           all other members of the 68000-family.
  770. Example: See part II
  771.  
  772. Instruction:   MOVE to/from USP
  773. Syntax:        MOVE USP,An   or   MOVE An,USP
  774. Data sizes:    Long
  775. Condition codes affected: None.
  776. Addressing modes: see Syntax
  777.  
  778.  
  779.  
  780. Function: This instruction is priviliged.  The instruction exists 
  781.           because the 68000 has in fact two stack-pointers.  They 
  782.           are both contained in a7.  This is possible because the 
  783.           68000 has two modes of operation: user- and supervisor-
  784.           mode.  When in usermode it is impossible to access  the 
  785.           supervisor  stackpointer.  It  is rather  logical  that 
  786.           there are in fact two stackpointers.  If there had been 
  787.           only  one  it would have been possible to mess  up  the 
  788.           stack  in  such  a way that  the  system  would  crash. 
  789.           However, the supervisor must have the ability to access 
  790.           the user-stackpointer (for parameter-passing etc.).
  791. Example:
  792. Instruction              Before         After
  793. MOVE USP,a6              USP=12345678   USP=12345678
  794.                          a6=33333333    a6=12345678
  795.  
  796. Instruction:   MOVEA
  797. Syntax:        MOVEA <ea>,An
  798. Data sizes:    Word, Long
  799. Condition codes affected: None
  800.  
  801.  
  802. Addressing modes:
  803. source:   Dn
  804.           An
  805.           (An)
  806.           (An)+
  807.           -(An)
  808.           w(An)
  809.           b(An,Rn)
  810.           w
  811.           l
  812.           w(PC)
  813.           b(PC,Rn)
  814.           #x
  815. destination:
  816.           An
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824. Function: Load an address register with a value. If the operation 
  825.           is word-sized then the address is  sign-extended.  Most 
  826.           assemblers will accept MOVE <ea>,An as well. However, I 
  827.           think it is better to write MOVEA instead of just MOVE. 
  828.           When  you  intend  to  move a  value  into  an  address 
  829.           register but you forget to specify an address  register 
  830.           and  specify  something else,  the assembler  will  not 
  831.           generate an error. E.g. you want to move $12345678 into 
  832.           a0.  MOVE.L #$12345678,d0   will not generate an error, 
  833.           while MOVEA.L #$12345678,d0 will generate an error.
  834. Example: See part II
  835.  
  836. Instruction:   MOVEM
  837. Syntax:        MOVEM register list,<ea>      or
  838.                MOVEM <ea>,register list
  839.                register list is a set of registers.  Suppose  you 
  840.                want  to  specify  all  data-register.  You  could 
  841.                write:  d0-d7  or d0/d1/d2/d3/d4/d5/d6/d7  or  d0-
  842.                d3/d4/d5-d7. A number of registers in a row can be 
  843.                denotated with a minus ('-') between them.  Single 
  844.                registers  can  be specified with  a  slash  ('/') 
  845.                between them.
  846. Data sizes:    Word or Long
  847. Condition codes affected: None
  848. Addressing modes:
  849. destination:
  850.           (An)
  851.           -(An)
  852.           w(An)
  853.           b(An,Rn)
  854.           w
  855.           l
  856. source:   (An)
  857.           (An)+
  858.           w(An)
  859.           b(An,Rn)
  860.           w
  861.           l
  862.           w(PC)
  863.           b(PC,Rn)
  864.  
  865.  
  866.  
  867.  
  868. Example:
  869. Instruction:             Before         After
  870. MOVEM.W $1000,d0/d3      $1000=$1234    d0=$1234
  871.                          $1002=$5678    d1=$5678
  872. MOVEM.L d0-d7/a0-a6,-(a7) will push all registers onto the stack.
  873. MOVEM.L (a7)+,d0-d7/a0-a6 will pull all registers from the stack.
  874.  
  875. Instruction:   MOVEP
  876. Syntax:        MOVEP Dn,w(An)   or   MOVEP w(An),Dn
  877. Data sizes:    Word, Long
  878. Condition codes affected: None
  879. Function: Transfer data from or to a peripheral. This instruction 
  880.           has been specially designed for communication with  all 
  881.           devices  which have been originally designed for  8-bit 
  882.           micro-processors.  This  way the 68000 can  communicate 
  883.           with these devices.  E.g.  in the Atari are two  ACIA's 
  884.           present.  ACIA's  are designed for 8-bit  computers.  I 
  885.           won't  explain the operation of this  instruction  here 
  886.           for it is rather seldom used,  especially by beginners. 
  887.           If  you  want  to know all  about  this  instruction  I 
  888.           suggest you contact the writer of this article.
  889.  
  890. Instruction:   MOVEQ
  891. Syntax:        MOVEQ #,Dn
  892. Data sizes:    Long
  893. Condition codes affected: See move.
  894. Function: This  instruction  provides an efficient way  (both  in 
  895.           space  and  time) to set a data register to  a  value). 
  896.           Values range from -128 to +127 decimal. Most assemblers 
  897.           will generate MOVEQ-instructions where possible.
  898. Example:
  899. Instruction              Before         After
  900. MOVEQ #$34,d0            d0=ffffffff    d0=00000034
  901.  
  902. Instruction:   PEA
  903. Syntax:        PEA <ea>
  904. Data sizes:    Long
  905. Condition codes affected: None
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912. Addressing modes:
  913. source:   (An)
  914.           w(An)
  915.           b(An,Rn)
  916.           w
  917.           l
  918.           w(PC)
  919.           b(PC,Rn)
  920. Function: Push  an address onto the stack.  This  instruction  is 
  921.           often used to write position independent code.  It  has 
  922.           nearly the same function as MOVE.L <ea>,-(a7).
  923. Example:
  924. Instruction              Before         After
  925. PEA (a6)                 a6=12345678    a6=12345678
  926.                          a7=44444444    a7=44444448
  927.  
  928. Instruction:   SWAP
  929. Syntax:        SWAP Dn
  930. Data sizes:    None
  931. Condition codes affected: V, C: always cleared
  932.                           Z set if the result is 0
  933.                           N set if bit 31 of the result is 1
  934. Function: exchange upper and lower half of a data register.  This 
  935.           instruction  is  often  used in  conjunction  with  the 
  936.           divide operation (will be explained further)
  937. Example:
  938. Instruction              Before         After
  939. SWAP d0                  d0=12345678    d0=56781234
  940.  
  941. Next  time I will discuss the integer arithmetic  operations.  By 
  942. the  way:  I'm beginning to believe that this course is the  best 
  943. there is,  since I don't get any comments!!! If you read this and 
  944. react you can earn yourself a surprise.
  945.  
  946.  
  947.  
  948. MC 68000 MACHINE LANGUAGE COURSE PART IV by Mark van den Boer
  949.  
  950. What a pity!!  You missed the mega-surprise of part 3.  Next time 
  951. better luck! I am gonna take that holiday to Hawaii myself!
  952.  
  953. This time I will discuss the Integer Arithmetic Instructions. The 
  954. syntax used is of course the same as in part 3,  so when in doubt 
  955. refer  to  part  3.  This class of instructions  is  used  to  do 
  956. mathematical  calculations.  This  group is very  often  used  by 
  957. assembly  language programmers,  especially the instructions  for 
  958. adding and subtracting.
  959.  
  960.  
  961. Integer Arithmetic Instructions
  962.  
  963.  
  964. Instruction:   ADD
  965. Syntax:        ADD Dn,<ea>
  966.                ADD <ea>,Dn
  967. Data sizes:    byte, word, long
  968.  
  969.  
  970. Condition codes affected:
  971.                X, C set by carry out of the most significant bit
  972.                N    set if the result was negative, cleared otherwise
  973.                Z    set if the result was zero, cleared otherwise
  974.                V    set if the result overflowed, cleared otherwise
  975. Addressing modes:
  976. Source: (destination is Dn)
  977.           Dn
  978.           An
  979.           (An)
  980.           (An)+
  981.           -(An)
  982.           w(An)
  983.           b(An,Rn)
  984.           w
  985.           l
  986.           w(PC)
  987.           b(PC,Rn)
  988.  
  989.  
  990.  
  991.  
  992. Destination:
  993.           Dn
  994.           (An)
  995.           (An)+
  996.           -(An)
  997.           w(An)
  998.           b(An,Rn)
  999.           w
  1000.           l
  1001. Function: Add  source  to  destination  and  put  the  result  in 
  1002.           destination.
  1003. Examples:
  1004. Instruction              Before         After
  1005. ADD.W d0,d1              d0=00000011    d0=00000011
  1006.                          d1=0000FFFA    d1=0000000B
  1007.                          XNZVC=00000    XNZVC=11001
  1008. ADD.L (a0),d0            d0=00000022    d0=00000027
  1009.                          a0=12345678    a0=12345678
  1010.                     12345678 contains 5
  1011.                          XNZVC=00000    XNZVC=00000
  1012.  
  1013.  
  1014. Instruction:   ADDA
  1015. Syntax:        ADDA <ea>,An
  1016. Data sizes:    word, long
  1017. Condition codes affected: None
  1018. Addressing modes:
  1019. Source:
  1020.           Dn
  1021.           An
  1022.           (An)
  1023.           (An)+
  1024.           -(An)
  1025.           w(An)
  1026.           b(An,Rn)
  1027.           w
  1028.           l
  1029.           w(PC)
  1030.           b(PC,Rn)
  1031.           #
  1032. Destination:
  1033.           An
  1034.  
  1035.  
  1036. Function: Add a value to an address register. This operation does 
  1037.           not change any of the condition code values.  Note that 
  1038.           most  operations  that have an address  register  as  a 
  1039.           destination does not change the condition codes.
  1040. Example:
  1041. Instruction              Before         After
  1042. ADDA.L a0,a0             a0=00000002    a0=00000004
  1043. Notice  that this instruction has the same effect as  multiplying 
  1044. the address register with two (if this was possible).
  1045.  
  1046.  
  1047. Instruction:   ADDI
  1048. Syntax:        ADDI #,<ea>
  1049. This instruction has exactly the same characteristics as the  ADD 
  1050. instruction, except that the source can only be a constant.
  1051.  
  1052. Instruction:   ADDQ
  1053. Syntax:        ADDQ #,<ea>
  1054. Same story as for ADDI,  except that the immediate values in  the 
  1055. source  field  can only range from 1 to 8.  Q stands  for  Quick, 
  1056. since this instruction is the fastest way to add a number from  1 
  1057. to 8 to a destination operand.
  1058. A note on ADD, ADDI, ADDQ:
  1059. Most assemblers accept the following instruction: ADD #1,Dn
  1060. and will translate it automatically to ADDQ #1,Dn    thus  saving 
  1061. a few bytes of object code and some clock cycles execution time.
  1062.  
  1063.  
  1064. Instruction:   ADDX
  1065. Syntax:        ADDX Dn,Dn
  1066.                ADDX -(An),-(An)
  1067. Data sizes:    byte, word, long
  1068. Condition codes affected: see ADD
  1069. Function: Add  X-bit  and  source to destination  and  store  the 
  1070.           result  in destination.  This instruction is  used  for 
  1071.           multiple  precision  operations and is  therefore  only 
  1072.           available with the two addressing modes mentioned.
  1073. Example:
  1074. Instruction              Before         After
  1075. ADDX.B -(a0),-(a1)       a0=10001001    a0=10001000
  1076.                          a1=10002001    a1=10002000
  1077.                  10001000 contains AA   the same
  1078.                  10002000 contains 5A   10002000 contains 4
  1079.                          X=0            X=1
  1080. ADDX.B -(a0),-(a1)        a0=10001000    a0=10000fff
  1081.                          a1=10002000    a1-10001fff
  1082.                  10000fff contains 0    the same
  1083.                  10001fff contains 0    10001fff contains 1
  1084.                          X=1            X=0
  1085. In this example the word that begins at 10000fff is added to  the 
  1086. word that begins at 10001fff.  If one should try to do this  with 
  1087. two  ADD.W instruction an address error would occur  since  words 
  1088. always must be aligned to even addresses. This instruction can be 
  1089. compared to the ADC instruction of the 6502 and 6809.
  1090.  
  1091.  
  1092. Instruction:   CLR
  1093. Syntax:        CLR <ea>
  1094. Data sizes:    byte, word, long
  1095. Condition codes affected:
  1096.                N    always cleared
  1097.                Z    always set
  1098.                V    always cleared
  1099.                C    always cleared
  1100.  
  1101.  
  1102. Addressing modes:
  1103.           Dn
  1104.           (An)
  1105.           (An)+
  1106.           -(An)
  1107.           w(An)
  1108.           b(An,Rn)
  1109.           w
  1110.           l
  1111. Function: Set an effective address to zero. You will have noticed 
  1112.           that you can't CLR an address register.  However,  most 
  1113.           assemblers  allow  the  programmer to  CLR  an  address 
  1114.           register  by  substituting CLR a0 with SUB.L  a0,a0   . 
  1115.           This instruction has exactly the same result.
  1116. Example:
  1117. Instruction              Before         After
  1118. CLR.W d0                 d0=ffffffff    d0=00000000
  1119.                          NZVC=1011      NZVC=0100
  1120.  
  1121.  
  1122.  
  1123.  
  1124. Instruction:   CMP
  1125. Syntax:        CMP <ea>,Dn
  1126. Data sizes:    byte, word, long
  1127. Condition codes affected: NZVC (X is not affected)
  1128. Addressing modes (source):
  1129.           Dn
  1130.           An
  1131.           (An)
  1132.           (An)+
  1133.           -(An)
  1134.           w(An)
  1135.           b(An,Rn)
  1136.           w
  1137.           l
  1138.           w(PC)
  1139.           b(PC,Rn)
  1140. Function: compare an effective address with a data  register.  In 
  1141.           fact  all  condition codes are set as  if  Dn-<ea>  was 
  1142.           performed.  So CMP is kind of a subtraction which  only 
  1143.           affects the conditon codes.
  1144.  
  1145.  
  1146. Example:
  1147. Instruction              Before         After
  1148. CMP.L d0,d1              d0=00000001    d0=00000001
  1149.                          d1=00000002    d1=00000002
  1150.                          NZVC=1111      NZVC=0000
  1151.  
  1152.  
  1153. Instruction:   CMPA
  1154. Syntax:        CMPA <ea>,An
  1155. Data sizes:    word, long
  1156. Function: This  instruction  differs only from CMP  in  that  the 
  1157.           second  operand  is an address register and  that  byte 
  1158.           isn't allowed as a data size.
  1159.  
  1160.  
  1161. Instruction:   CMPI
  1162. Syntax:        CMPI #,Dn
  1163. Function: Yes,  it is nearly exactly the same as compare but  now 
  1164.           the first operand must be a constant.
  1165.  
  1166.  
  1167.  
  1168. Instruction:   CMPM
  1169. Syntax:        CMPM (An)+,(An)+
  1170. Function: Again, nearly exactly the same as CMP, but now both the 
  1171.           source  and  destination operand must  be  (An)+.  This 
  1172.           instruction  is used to compare areas  of  memory.  For 
  1173.           those of you who have a working knowledge of C:  strcmp 
  1174.           can be programmed easy with this instruction.
  1175.  
  1176. Note on all CMPx instructions.
  1177. Most assemblers accept instructions like:
  1178. CMP.W (a0)+,(a1)+
  1179. CMP.L #3,d0
  1180. Substitution of CMPM,  CMPI and CMPA are automatically  performed 
  1181. by the assembler.
  1182.  
  1183.  
  1184. Instruction:   DIVS
  1185. Syntax:        DIVS <ea>,Dn
  1186. Data sizes:    word
  1187.  
  1188.  
  1189.  
  1190. Condition codes affected:
  1191.                N    behaves normal; undefined on overflow
  1192.                Z    behaves normal; undefined on overflow
  1193.                V    behaves normal
  1194.                C    always cleared
  1195. Addressing modes (source):
  1196.           Dn
  1197.           (An)
  1198.           (An)+
  1199.           -(An)
  1200.           w(An)
  1201.           b(An,Rn)
  1202.           w
  1203.           l
  1204.           w(PC)
  1205.           b(PC,Rn)
  1206.           #
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212. Function: Guess  what?   This  instruction  performs  a  division 
  1213.           between two signed numbers. The 
  1214.           destination  register  is  always a  longword  and  the 
  1215.           source operand is always a word. After the division the 
  1216.           destination operand contains the result.  The  quotient 
  1217.           is always in the lower word and the remainder is always 
  1218.           in the high order word of the data register! This way a 
  1219.           modulo operation is also performed,  you just SWAP  the 
  1220.           data  register  and you have your result in  the  lower 
  1221.           word  of the data register.  Overflow occurs  when  you 
  1222.           attempt to divide a large number by a small number e.g. 
  1223.           ffffff divided by 1,  the result doesn't fit in a word. 
  1224.           Another error occurs when attempting to divide by zero. 
  1225.           In this case the 68000 generates an exception and  will 
  1226.           trap  to  a special routine which handles  division  by 
  1227.           zero erros.  On the Atari you must set up this  routine 
  1228.           yourself.  E.g.  FLOYD  (a  machine  language  monitor) 
  1229.           responds  to  a  division by zero  with  the  following 
  1230.           sentence "The answer is 42". Remember, don't panic when 
  1231.           you see such an answer.
  1232.  
  1233.  
  1234. Example:
  1235. Instruction              Before         After
  1236. DIVS #3,d0               d0=0000000B    d0=00020003
  1237.                          NZVC=1111      NZVC=0000
  1238.  
  1239.  
  1240. Instruction: DIVU
  1241. Function: Nearly  exactly the same as DIVS,  only this time  both 
  1242.           operands are assumed to be unsigned.
  1243.  
  1244.  
  1245. Instruction:   EXT
  1246. Syntax:        EXT Dn
  1247. Data sizes:    word, long
  1248. Condition codes affected:
  1249.                N    behaves normal
  1250.                Z    behaves normal
  1251.                V    always cleared
  1252.                C    always cleared
  1253.  
  1254.  
  1255.  
  1256. Function: turn  a byte into a word,  or turn a word into a  long. 
  1257.           This  instruction provides a convenient way to  turn  a 
  1258.           word into a long and still have the same value for that 
  1259.           register. If the high order bit of the data register is 
  1260.           0,  so the data register is positive, zeroes are padded 
  1261.           in, otherwise ones are padded in.
  1262. Example:
  1263. Instruction              Before         After
  1264. EXT.W d0                 d0=000000ff    d0=0000ffff
  1265. EXT.L d0                 d0=ffff0000    d0=00000000
  1266.  
  1267.  
  1268. Instruction:   MULS
  1269. Syntax:        MULS <ea>,Dn
  1270. Data sizes:    word
  1271. Condition codes affected:
  1272.                N    behaves normal
  1273.                Z    behaves normal
  1274.                V    always cleared
  1275.                C    always cleared
  1276.  
  1277.  
  1278. Addressing modes (source):
  1279.           Dn
  1280.           (An)
  1281.           (An)+
  1282.           -(An)
  1283.           w(An)
  1284.           b(An,Rn)
  1285.           w
  1286.           l
  1287.           w(PC)
  1288.           b(PC,Rn)
  1289.           #
  1290. Function: Ah!  another very handy instruction.  This  instruction 
  1291.           performs a multiplication of the source and destination 
  1292.           operand, putting the result in the destination operand.
  1293. Example:
  1294. Instruction              Before         After
  1295. MULS #3,d0               d0=0000000B    d0=00000021
  1296.                          NZVC=1111      NZVC=0000
  1297.  
  1298.  
  1299.  
  1300. Instruction: MULU
  1301. Function: Nearly  exactly the same as MULUS,  only this time  both 
  1302.           operands are assumed to be unsigned.
  1303.  
  1304.  
  1305. Instruction:   NEG
  1306. Syntax:        NEG <ea>
  1307. Data sizes:    byte, word, long
  1308. Condition codes affected: XNZVC (all behave normal)
  1309. Addressing modes:
  1310.           Dn
  1311.           (An)
  1312.           (An)+
  1313.           -(An)
  1314.           w(An)
  1315.           b(An,Rn)
  1316.           w
  1317.           l
  1318. Function: negate  an effective address operand.  In a high  level 
  1319.           language it would look like this: a = -a
  1320.  
  1321.  
  1322. Example:
  1323. Instruction              Before         After
  1324. NEG.L d0                 d0=00000001    d0=ffffffff
  1325.  
  1326.  
  1327. Instruction:   NEGX
  1328. Syntax:        NEGX <ea>
  1329. Data sizes:    byte, word, long
  1330. Condition codes affected: XNZVC (all behave normal)
  1331. Addressing modes:
  1332.           Dn
  1333.           (An)
  1334.           (An)+
  1335.           -(An)
  1336.           w(An)
  1337.           b(An,Rn)
  1338.           w
  1339.           l
  1340. Function: negate  an effective address operand and add the  X-bit 
  1341.           to  the  result.  This  is  another  instruction  which 
  1342.           provides a way to handle multi-precision  (e.g.  8-byte 
  1343.           integers).
  1344. Example:
  1345. Instruction              Before         After
  1346. NEGX.L d0                d0=00000001    d0=00000000
  1347.                          X=1            X=1
  1348.  
  1349.  
  1350. Instructions: SUB, SUBA, SUBI, SUBQ, SUBX
  1351. All these instruction perform subtractions.  They only differ  in 
  1352. that   way   from   from  the   ADD   instructions,   all   other 
  1353. characteristics are the same.
  1354.  
  1355.  
  1356. Instruction:   TAS
  1357. Syntax:        TAS <ea>
  1358. Data sizes:    byte
  1359. Condition codes affected:
  1360.                N    evaluated before setting the byte
  1361.                Z    evaluated before setting the byte
  1362.                V    always cleared
  1363.                C    always cleared
  1364.  
  1365.  
  1366. Addressing modes:
  1367.           Dn
  1368.           (An)
  1369.           (An)+
  1370.           -(An)
  1371.           w(An)
  1372.           b(An,Rn)
  1373.           w
  1374.           l
  1375. Function: First  test  the operand and set the  condition  codes, 
  1376.           then set the high-order bit to 1.  People who know what 
  1377.           semaphores (in programming of course...) are,  immedia-
  1378.           tely  will love this instruction.  For those who  don't 
  1379.           know what semaphores are: M. Ben Ari has written a good 
  1380.           book  on the subject called "Principles  of  Concurrent 
  1381.           Programming".  Never,  I repeat never,  read a book  on 
  1382.           this subject written by a certain Ir.  E.H.H.  Dijkstra 
  1383.           (not the famous Dijkstra,  this Dijkstra will never  be 
  1384.           famous).
  1385.  
  1386.  
  1387.  
  1388. Example:
  1389. Instruction              Before         After
  1390. TAS $436                 $436=00        $436=80
  1391.                          NZVC=1111      NZVC=0100
  1392. TAS $436                 $436=FF        $436=FF
  1393.                          NZVC=1111      NZVC=1000
  1394.  
  1395.  
  1396. Instruction:   TST
  1397. Syntax:        TST <ea>
  1398. Data sizes:    byte, word, long
  1399. Condition codes affected:
  1400.                N    behaves normal
  1401.                Z    behaves normal
  1402.                V    always cleared
  1403.                C    always cleared
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410. Addressing modes:
  1411.           Dn
  1412.           (An)
  1413.           (An)+
  1414.           -(An)
  1415.           w(An)
  1416.           b(An,Rn)
  1417.           w
  1418.           l
  1419. Function: test an effective address operand. This instruction can 
  1420.           be  seen as CMP <ea>,d0 where d0 is 0.  TST  is  nearly 
  1421.           always followed by a branch instruction (more on  these 
  1422.           later)
  1423.  
  1424.  
  1425.  
  1426. MACHINE LANGUAGE COURSE PART V by Mark van den Boer
  1427.  
  1428. Logical Operations
  1429.  
  1430. Instruction:   AND
  1431. Syntax:        AND <ea>,Dn
  1432.                AND Dn,<ea>
  1433. Data sizes:    byte, word, long
  1434. Condition codes affected:
  1435.                X    not affected
  1436.                N    set to the most significant bit of the result
  1437.                Z    set if the result is zero, cleared otherwise
  1438.                V,C  always cleared
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448. Addressing modes:
  1449. Source: (destination is Dn)
  1450.           Dn
  1451.           (An)
  1452.           (An)+
  1453.           -(An)
  1454.           w(An)
  1455.           b(An,Rn)
  1456.           w
  1457.           l
  1458.           w(PC)
  1459.           b(PC,Rn)
  1460. Destination: (source is Dn)
  1461.           (An)
  1462.           (An)+
  1463.           -(An)
  1464.           w(An)
  1465.           b(An,Rn)
  1466.           w
  1467.           l
  1468. Function: Perform   a   boolean  bitwise  AND   from   source   to 
  1469.           destination.
  1470. Examples:
  1471. Instruction              Before         After
  1472. AND.B d0,d1              d0=33333333    d0=33333333
  1473.                          d1=ffffffff    d1=ffffffcc
  1474. AND.W d0,d1              d0=33333333    d0=33333333
  1475.                          d1=ffffffff    d1=ffffcccc
  1476. AND.L d0,d1              d0=33333333    d0=33333333
  1477.                          d1=ffffffff    d1=cccccccc
  1478.  
  1479.  
  1480. Instruction:   ANDI
  1481. Syntax:        ANDI #,<ea>
  1482. Data sizes:    byte, word, long
  1483. Condition codes affected:
  1484.                X    not affected
  1485.                N    set to the most significant bit of the result
  1486.                Z    set if the result is zero, cleared otherwise
  1487.                V,C  always cleared
  1488.  
  1489.  
  1490.  
  1491.  
  1492. Addressing modes:
  1493. Destination:
  1494.           Dn
  1495.           (An)
  1496.           (An)+
  1497.           -(An)
  1498.           w(An)
  1499.           b(An,Rn)
  1500.           w
  1501.           l
  1502.           CCR, SR
  1503. Function: Perform   a   boolean  bitwise  AND   from   source   to 
  1504.           destination.
  1505. Examples:
  1506. Instruction              Before         After
  1507. ANDI.B #7,d0             d0=33333333    d0=33333330
  1508. ANDI.W #$ff00,SR         SR=ffff        SR=ff00
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514. Instruction:   EOR
  1515. Syntax:        EOR Dn,<ea>
  1516. Data sizes:    byte, word, long
  1517. Condition codes affected:
  1518.                X    not affected
  1519.                N    set to the most significant bit of the result
  1520.                Z    set if the result is zero, cleared otherwise
  1521.                V,C  always cleared
  1522. Addressing modes:
  1523. Destination:
  1524.           Dn
  1525.           (An)
  1526.           (An)+
  1527.           -(An)
  1528.           w(An)
  1529.           b(An,Rn)
  1530.           w
  1531.           l
  1532.  
  1533.  
  1534.  
  1535.  
  1536. Function: Perform  a bitwise exclusive or from source to  destina-
  1537.           tion.  You  will notice that this instruction  can  only 
  1538.           take a data register as the source,  unlike the AND  and 
  1539.           OR  instructions.  I  think the designers of  the  68000 
  1540.           should have mode addressing modes more orthogonal.
  1541. Examples:
  1542. Instruction              Before         After
  1543. EOR.L d0,d1              d0=ffffffff    d0=ffffffff
  1544.                          d1=f0f0f0f0    d1=0f0f0f0f
  1545.  
  1546.  
  1547. Instruction:   EORI
  1548. Syntax:        EORI #,<ea>
  1549. Data sizes:    byte, word, long
  1550. Condition codes affected:
  1551.                X    not affected
  1552.                N    set to the most significant bit of the result
  1553.                Z    set if the result is zero, cleared otherwise
  1554.                V,C  always cleared
  1555.  
  1556.  
  1557.  
  1558. Addressing modes:
  1559. Destination:
  1560.           Dn
  1561.           (An)
  1562.           (An)+
  1563.           -(An)
  1564.           w(An)
  1565.           b(An,Rn)
  1566.           w
  1567.           l
  1568.           CCR, SR
  1569. Function: Perform   a   bitwise  exclusive  or  from   source   to 
  1570.           destination.
  1571. Examples:
  1572. Instruction              Before         After
  1573. EORI.B #$ff,d0           d0=33333330    d0=333333cf
  1574. EORI.W #$00ff,SR         SR=ff32        SR=ffcd
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580. Instruction:   NOT
  1581. Syntax:        NOT <ea>
  1582. Data sizes:    byte, word, long
  1583. Condition codes affected:
  1584.                X    not affected
  1585.                N    set to the most significant bit of the result
  1586.                Z    set if the result is zero, cleared otherwise
  1587.                V,C  always cleared
  1588. Addressing modes:
  1589. Destination:
  1590.           Dn
  1591.           (An)
  1592.           (An)+
  1593.           -(An)
  1594.           w(An)
  1595.           b(An,Rn)
  1596.           w
  1597.           l
  1598. Function: Perform a bitwise not to the effective address  operand. 
  1599.           Note that NOT.W d0 is the same as EORI.W #$ffff,d0.
  1600.  
  1601.  
  1602. Examples:
  1603. Instruction              Before         After
  1604. NOT.B #$ff,d0            d0=ffffff78    d0=ffffff87
  1605.  
  1606.  
  1607. Instruction:   OR
  1608. Syntax:        OR <ea>,Dn
  1609.                OR Dn,<ea>
  1610. Data sizes:    byte, word, long
  1611. Condition codes affected:
  1612.                X    not affected
  1613.                N    set to the most significant bit of the result
  1614.                Z    set if the result is zero, cleared otherwise
  1615.                V,C  always cleared
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624. Addressing modes:
  1625. Source: (destination is Dn)
  1626.           Dn
  1627.           (An)
  1628.           (An)+
  1629.           -(An)
  1630.           w(An)
  1631.           b(An,Rn)
  1632.           w
  1633.           l
  1634.           w(PC)
  1635.           b(PC,Rn)
  1636. Destination: (source is Dn)
  1637.           (An)
  1638.           (An)+
  1639.           -(An)
  1640.           w(An)
  1641.           b(An,Rn)
  1642.           w
  1643.           l
  1644. Function: Perform a boolean bitwise OR from source to destination.
  1645.  
  1646. Examples:
  1647. Instruction              Before         After
  1648. OR.B d0,d1               d0=ffffffff    d0=ffffffff
  1649.                          d1=33333333    d1=333333ff
  1650. OR.W d0,d1               d0=ffffffff    d0=ffffffff
  1651.                          d1=33333333    d1=3333ffff
  1652. OR.L d0,d1               d0=ffffffff    d0=ffffffff
  1653.                          d1=33333333    d1=ffffffff
  1654.  
  1655.  
  1656. Instruction:   ORI
  1657. Syntax:        ORI #,<ea>
  1658. Data sizes:    byte, word, long
  1659. Condition codes affected:
  1660.                X    not affected
  1661.                N    set to the most significant bit of the result
  1662.                Z    set if the result is zero, cleared otherwise
  1663.                V,C  always cleared
  1664.  
  1665.  
  1666.  
  1667.  
  1668. Addressing modes:
  1669. Destination:
  1670.           Dn
  1671.           (An)
  1672.           (An)+
  1673.           -(An)
  1674.           w(An)
  1675.           b(An,Rn)
  1676.           w
  1677.           l
  1678.           CCR, SR
  1679. Function: Perform  a boolean bitwise OR from source  to  destina-
  1680.           tion.
  1681. Examples:
  1682. Instruction              Before         After
  1683. ORI.B #7,d0               d0=33333330    d0=33333333
  1684. ORI.W #$00ff,SR           SR=ff00        SR=ffff
  1685.  
  1686.  
  1687. Now load parts 6-10.